package cn.rocksolid.sport.assist.config;

import java.util.Map;

import org.apache.commons.collections4.MapUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import cn.rocksolid.sport.common.Constant.IdCardVerifierType;
import cn.rocksolid.sport.common.error.RSE;
import cn.rocksolid.sport.common.error.RockSolidException;

/**
 * The configuration class for IdCard validation provider configuration
 */

@ConfigurationProperties(prefix = "rocksolid")
@Component
public class IdCardVerifierConfig {

  private Map<IdCardVerifierType, Map<String, Map<String, String>>> idCardVerifierConfigs;

  public Map<IdCardVerifierType, Map<String, Map<String, String>>> getIdCardVerifierConfigs() {
    return idCardVerifierConfigs;
  }

  public void setIdCardVerifierConfigs(
      Map<IdCardVerifierType, Map<String, Map<String, String>>> idCardVerifierConfigs) {
    if (MapUtils.isNotEmpty(idCardVerifierConfigs)) {
      for (Map.Entry<IdCardVerifierType, Map<String, Map<String, String>>> configEntry : idCardVerifierConfigs
          .entrySet()) {
        if (!configEntry.getValue().containsKey(ConfigConst.DEFAULT_CONF)) {
          throw new RockSolidException(RSE.MISS_IVP_DC);
        }
      }
    }
    this.idCardVerifierConfigs = idCardVerifierConfigs;
  }
}
